home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 6
/
CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso
/
cucd
/
readers
/
utils
/
gui4cli
/
demos
/
calc.gc
next >
Wrap
Text File
|
1996-10-28
|
11KB
|
425 lines
G4C
; CALC.gc
; A calculator, based on the EVAL cli command, which should
; be in your c: directory.
; What we do here, is make a gui to construct the calculation formula
; that we will pass to EVAL, for us to solve.
; EVAL will read in the formula and place the result in an env: Variable
; we tell it. From there, we read it and redisplay it to the user.
; Not satisfied with our above incredible feat, we go on to add 5 memories,
; and Octal and Hex conversion. (somebody stop me!)
; The only fault in this program, is that EVAL will not support floating
; point numbers, so we can't have decimals. If someone were to write
; a little program that did support decimals, and preferably AREXX too,
; then this could be a calculator everyone could adjust to his tastes.
; PS : I wrote the above before seeing GUIs:G4C/Various/FPCalc.gc,
; by G.Maddox, where he uses ARexx's calculating capabilities to
; make an excellent floating point calc.. oh well.. I'll change it next
; time..
WINBIG 400 24 223 155 "EVAL" ; Our window.
WinType 11110001 ; It has all standard gadgets & bottom resize
WinSmall 0 -1 181 122 ; The minimum size of our window
WINOUT "NIL:" ; We don't want any output.
WINBACKGROUND PATTERN 0 2 ; Add a flashy background..
;NoFontSense
;***************************** GRAPHICS **************************************
line 10 90 213 90 1 ; Some lines, for unparalleled dramatic effect.
line 10 91 213 91 2
line 85 112 213 112 1
line 86 113 213 113 2
line 85 112 85 129 1
line 86 113 86 130 2
line 10 129 85 129 1
line 10 130 86 130 2
BOX 0 0 0 0 OUT ICONDROP ; A window sized box, taking us way beyond "cool"
;************************** GENERAL EVENTS ***********************************
xAPPICON 0 0 guis:info/calc "Calculator" "" OFF ; An AppIcon which when
GadID 10 ; clicked on will
GuiOpen calc.gc ; open the calculator.
xONOPEN ; Every time the window opens,
SetGad calc.gc 10 OFF ; we remove the above AppIcon
GuiScreen calc.gc FRONT ; and bring the screen to the front.
xONCLOSE ; Every time the user closes the window,
SetGad calc.gc 10 ON ; we make the AppIcon re-appear.
xONLOAD ; Upon loading of the GUI
setvar calcvar "" ; This is our main variable
GUIOPEN calc.gc
RUN 'resident c:eval ADD' ; Make eval resident, for speed.
setvar lformat "%N" ; This is the display format we want
setvar mem .mem1 ; These are the Memory variables
setvar .mem1 0 ; The ones starting with a full stop,
setvar .mem2 0 ; are env: variables
setvar .mem3 0
setvar .mem4 0
setvar .mem5 0
setvar membuff ""
setvar .result "0" ; somewhere to put the result (env: variable)
xOnQuit ; On quitting we delete the env variables,
delete env:.mem#? ; so they don't linger in Env:
delvar calcvar
delvar lformat
delvar mem
delvar membuff
delvar .result
RUN "Resident eval remove" ; Remove eval from the resident list
;********************************* MENUS *************************************
; Below are the Menus for our calculator. They are pretty basic.
xMENU Calculator About... "" A
EZREQ "Calculator made with Gui4Cli\nUsing the c:Eval command" "Incredible !!" CalcReq
xMENU Calculator BARLABEL "" ""
xMENU calculator Quit "" Q
GUIQUIT calc.gc
xMENU Options Screen Workbench "" ; This will place the calc on the WB screen
SetScreen calc.gc Workbench ; Set screen to workbench
gosub calc.gc ScreenChange ; See routine "ScreenChange"
xMENU Options Screen CygnusEd "" ; Place it on CygnusEd screen
SetScreen calc.gc CygnusEdScreen1
gosub calc.gc ScreenChange
xMENU Options Screen GoldEd "" ; GoldEd screen
SetScreen calc.gc GOLDED.1
gosub calc.gc ScreenChange
xROUTINE ScreenChange ; Routine to change screen
GuiClose calc.gc ; Close & reopen window, so that change
GuiOpen calc.gc ; takes effect
GuiScreen calc.gc FRONT ; bring window's screen to front
xMENU Options Display Decimal D ; Change Decimal/Octal/Hex
update calc.gc 2 0
gosub calc.gc FormatChange
xMENU options display Octal C
update calc.gc 2 2
gosub calc.gc FormatChange
xMENU options display Hex H
update calc.gc 2 1
gosub calc.gc FormatChange
xMENU options BARLABEL "" ""
xMENU options Calculate "" ""
gosub calc.gc calculate
xMENU options Clear "" C
update calc.gc 1 0
setvar calcvar ""
;*****************************************************************************
;***************************** BUTTONS GALORE ! ******************************
; All these buttons do the same thing. They AppVar their number or letter
; to our main variable and redisplay it
;=======================> The Buttons for the plain numbers
xBUTTON 10 25 25 15 1
gadkey 1 ; Keyboard shortcut
AppVar calcvar 1 ; AppVar the number to "calcvar"
update calc.gc 1 $calcvar ; and re-display it.
xBUTTON 36 25 25 15 2 ; same as above
gadkey 2
AppVar calcvar 2
update calc.gc 1 $calcvar
xBUTTON 62 25 25 15 3
gadkey 3
AppVar calcvar 3
update calc.gc 1 $calcvar
xBUTTON 10 41 25 15 4
gadkey 4
AppVar calcvar 4
update calc.gc 1 $calcvar
xBUTTON 36 41 25 15 5
gadkey 5
AppVar calcvar 5
update calc.gc 1 $calcvar
xBUTTON 62 41 25 15 6
gadkey 6
AppVar calcvar 6
update calc.gc 1 $calcvar
xBUTTON 10 57 25 15 7
gadkey 7
AppVar calcvar 7
update calc.gc 1 $calcvar
xBUTTON 36 57 25 15 8
gadkey 8
AppVar calcvar 8
update calc.gc 1 $calcvar
xBUTTON 62 57 25 15 9
gadkey 9
AppVar calcvar 9
update calc.gc 1 $calcvar
xBUTTON 10 73 25 15 0
gadkey 0
AppVar calcvar 0
update calc.gc 1 $calcvar
;=========================> The operators
xBUTTON 90 25 25 15 /
gadkey /
AppVar calcvar /
update calc.gc 1 $calcvar
xBUTTON 90 41 25 15 *
gadkey *
AppVar calcvar *
update calc.gc 1 $calcvar
xBUTTON 90 57 25 15 -
gadkey -
AppVar calcvar -
update calc.gc 1 $calcvar
xBUTTON 90 73 25 15 +
gadkey +
AppVar calcvar +
update calc.gc 1 $calcvar
xBUTTON 116 25 25 15 &
gadkey &
AppVar calcvar &
update calc.gc 1 $calcvar
xBUTTON 116 41 25 15 |
gadkey |
AppVar calcvar |
update calc.gc 1 $calcvar
xBUTTON 116 57 25 15 (
gadkey (
AppVar calcvar (
update calc.gc 1 $calcvar
xBUTTON 116 73 25 15 )
gadkey )
AppVar calcvar )
update calc.gc 1 $calcvar
xBUTTON 142 25 35 15 >>
gadkey >>
AppVar calcvar >>
update calc.gc 1 $calcvar
xBUTTON 142 41 35 15 <<
gadkey <<
AppVar calcvar <<
update calc.gc 1 $calcvar
xBUTTON 142 57 35 15 _mod
AppVar calcvar mod
update calc.gc 1 $calcvar
xBUTTON 142 73 35 15 ~
gadkey ~
AppVar calcvar ~
update calc.gc 1 $calcvar
xBUTTON 178 25 35 15 x_or
AppVar calcvar xor
update calc.gc 1 $calcvar
xBUTTON 178 41 35 15 _eqv
AppVar calcvar eqv
update calc.gc 1 $calcvar
xBUTTON 178 57 35 15 BSP ; This is a BackSpace button
gadkey #8
cutvar calcvar CUT CHAR -1 "" ; It will delete the last character of
update calc.gc 1 $calcvar ; "calcvar" and re-display it
xBUTTON 178 73 35 15 CLR
gadkey #127
update calc.gc 1 0 ; Clear button
setvar calcvar ""
;==========================> Calculate the result and display it.
xBUTTON 36 73 51 15 =
gadkey #13
gosub calc.gc calculate ; GoSub the routine which does the calculation
;===========================> This is our display panel. - Note it's
; a xTEXTin type gadget, so we can enter a calculation directly into it.
xTEXTIN 10 5 203 15 "" calcvar "Hello There!" 160
GADID 1
;===========================> Buttons for HEX input
xBUTTON 10 95 25 15 A
gadkey A
AppVar calcvar A
update calc.gc 1 $calcvar
xBUTTON 36 95 25 15 B
gadkey B
AppVar calcvar B
update calc.gc 1 $calcvar
xBUTTON 62 95 25 15 C
gadkey C
AppVar calcvar C
update calc.gc 1 $calcvar
xBUTTON 88 95 25 15 D
gadkey D
AppVar calcvar D
update calc.gc 1 $calcvar
xBUTTON 114 95 25 15 E
gadkey E
AppVar calcvar E
update calc.gc 1 $calcvar
xBUTTON 140 95 25 15 F
gadkey F
AppVar calcvar F
update calc.gc 1 $calcvar
; These two are for octal (#Number) and hex (#xNumber) input
xBUTTON 170 95 20 15 #
AppVar calcvar #
update calc.gc 1 $calcvar
xBUTTON 191 95 20 15 x
gadkey x
AppVar calcvar x
update calc.gc 1 $calcvar
;==========================> and a cycler to choose which format we want
; NOTE : Eval needs a number in the hex and octal display format, stating
; how many digits it should display. The maximum is 9 (I think).
xCYCLER 10 112 70 15 "" lformat
GADID 2
CSTR DEC %N ; These are the arguments that EVAL needs to give
CSTR HEX #x%X9 ; us the required display.
CSTR OCT #%O9
gadkey H
gosub calc.gc FormatChange
;****************************** ROUTINES *************************************
;===================> routine to calculate & display result
xROUTINE calculate
if $calcvar > "" ; If there is an entry
CLI 'eval $calcvar TO env:.result LFORMAT= $lformat' ; send it to EVAL
update calc.gc 1 $.result ; and display the answer EVAL returned
setvar calcvar $.result ; We set "calcvar" to the result
if $calcvar = 0
setvar calcvar "" ; and if it's 0, we empty it (looks nicer)
endif
endif
;==================> routine to show result in DEC/OCT/HEX format
; Basically the same routine as above.
xROUTINE FormatChange
if $calcvar = ""
setvar calcvar 0
endif
CLI 'eval $calcvar TO env:.result LFORMAT= $lformat'
update calc.gc 1 $.result
setvar calcvar $.result
if $calcvar = 0
setvar calcvar ""
endif
;*****************************************************************************
;***************************** MEMORIES **************************************
; If you look at the following code carefully, you will see that we
; need a variable within a variable.
; We use "membuff" to construct such a variable.
; This may be a little hard to understand, but it's nothing you'll need.
; If you don't understand it, it's not important.
;=======================> Memories display panel
xTEXTIN 91 116 123 15 "" $mem 0 30
GadID 5
;=======================> Memories cycler
xCycler 10 134 70 15 "" mem
Cstr "M1" .mem1
Cstr "M2" .mem2
Cstr "M3" .mem3
Cstr "M4" .mem4
Cstr "M5" .mem5
setvar membuff "\$$mem" ; This means set membuff to $ + whatever is in "mem"
update calc.gc 5 $membuff ; so that it points to the correct variable
;=======================> Memory IN/OUT
xButton 80 134 33 15 IN ; These buttons do the usual MEM in/out/+/-
SetVar $mem $calcvar ; stuff that calculators do.
setvar membuff "\$$mem"
update calc.gc 5 $membuff
xButton 113 134 33 15 OUT
setvar membuff "\$$mem"
AppVar calcvar $membuff
update calc.gc 1 $calcvar
xButton 146 134 33 15 M+
setvar membuff "\$$mem"
CLI 'eval $calcvar + $membuff TO env:$mem'
setvar membuff "\$$mem"
update calc.gc 5 $membuff
xButton 179 134 33 15 M-
setvar membuff "\$$mem"
CLI 'eval $membuff - $calcvar TO env:$mem'
setvar membuff "\$$mem"
update calc.gc 5 $membuff